import "reflect-metadata"
import {Key} from "./common";
import {PropertyMetadataManager} from "./PropertyMetadataManager";
import {ParamMetadataManager} from "./ParamMetadataManager";
import {MethodMetadataManager} from "./MethodMetadataManager";
import {ClassMetadataManager} from "./ClassMetadataManager";

export class MetadataCenter {
	/**
	 * 元数据宿主类的类名
	 */
	public readonly className: Key;

	public readonly propertyMetadataManager: PropertyMetadataManager;
	public readonly paramMetadataManager: ParamMetadataManager;
	public readonly methodMetadataManager: MethodMetadataManager;
	public readonly classMetadataManager: ClassMetadataManager;

	constructor(klass: Function) {
		this.className = klass.name;
		this.propertyMetadataManager = new PropertyMetadataManager();
		this.paramMetadataManager = new ParamMetadataManager();
		this.methodMetadataManager = new MethodMetadataManager();
		this.classMetadataManager = new ClassMetadataManager();
	}

	private static readonly METADATA_CENTER = "MetadataCenter";

	public static getManager(klass: Function): MetadataCenter | undefined {
		return Reflect.getMetadata(this.METADATA_CENTER, klass);
	}
}